#ifndef PROXY_H_
#define PROXY_H_

#include <vector>
#include <list>
#include "ConnectContext.h"
#include "Lock.h"


class Proxy
{
public:
    Proxy();
    ~Proxy();

    bool run();
    void stop();

private:
    bool _initialize();
    void _uninitialize();
    bool _createListenSocket();

    static DWORD WINAPI _workerThreadProc(LPVOID lpParam);
    DWORD _workerThreadProc();

    HANDLE _iocp;
    HANDLE _shutdownEvent;
    std::vector<HANDLE> _threads;

    SOCKET _listenSocket; 

    typedef std::list<ConnectContext*> Connections;
    Connections _connections;
    CriticalSection _cs;

private:
    ConnectContext* _createConnection();
    void _deleteConnection(ConnectContext* connection);
    void _clearConnections();
    void _closeBridge(BridgeContext* bridge);
};


#endif //PROXY_H_